<?php
    
	include_once "include/constants.php";
	
    define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

    function getUserRatings($friends) {
		$friends = substr_replace($friends, "", -1);;
		try {
			$conn = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS);
			$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    
			 
			$stmt = $conn->prepare('select * from user_ratings where movieid not in (select distinct movieid from movienights where id in (select movienightid from movienightstousers where userid in ('.$friends.')));');
			$stmt->execute();
			
			$userRatings = array();
			while ($row = $stmt->fetch()) {
				if (!isset($userRatings[$row['userid']])) {
					$userRatings[$row['userid']] = array();
				}
				$userRatings[$row['userid']][$row['movieid']] = $row['rating'];
			}
			return $userRatings;
			
		} catch(PDOException $e) {
			echo 'ERROR: ' . $e->getMessage();
		}
	}
?>
